<?php
/*
本系统由苏酷伊基于SiteHub项目二次开发
作者博客： https://www.sukuy.com/
后续更新地址： https://www.sukuy.com/navigation
作者QQ：3288637559
QQ交流群：884250547
任何第三方非官网在发布本系统时，不得删除该注释、版权信息、作者信息及官网等内容
*/
require('./includes/common.php');
$seconds = '3';
$refresh = '2';
$cur_time = time();
if (isset($_SESSION['last_time'])) {
    $_SESSION['refresh_times'] += 1;
} else {
    $_SESSION['refresh_times'] = 1;
    $_SESSION['last_time'] = $cur_time;
}
if ($cur_time - $_SESSION['last_time'] < $seconds) {
    if ($_SESSION['refresh_times'] >= $refresh) {
        sysmsg('<div style="color: red; font-size: 50px;">你是打算刷排行榜吗？！</div>');
    }
} else {
    $_SESSION['refresh_times'] = 0;
    $_SESSION['last_time'] = $cur_time;
}

$id = _get('id');
$alias = _get('alias');
if (empty($id) && empty($alias)) {
    exit('<script type="text/javascript">window.location.href="404.html";</script>');
};

if (empty($alias)) {
    $site_item = $DB->find('site', '*', array('id' => $id));
} else {
    $site_item = $DB->find('site', '*', array('alias' => $alias));
}
if (empty($site_item)) {
    exit('<script type="text/javascript">window.location.href="404.html";</script>');
};

require('./includes/lang.class.php');

$date = date("Y-m-d", time());
$datem = date("Y-m", time());
$zero1 = strtotime($date);
$zero2 = strtotime($datem);

$rdate = $site_item['date'];
$datey = $site_item['datem'];
$zero11 = strtotime($rdate);
$zero22 = strtotime($datey);
$update_data = array();
if ($zero1 == $zero11 and $zero2 == $zero22) {
    $update_data = array(
        'hits_total' => $site_item['hits_total'] + 1,
        'hits_month' => $site_item['hits_month'] + 1,
        'hits_day' => $site_item['hits_day'] + 1
    );
} elseif ($zero11 < $zero1 and $zero2 == $zero22) {
    $update_data = array(
        'hits_total' => $site_item['hits_total'] + 1,
        'hits_month' => $site_item['hits_month'] + 1,
        'hits_day' => 1,
        'date' => $date
    );
} elseif ($zero2 > $zero22) {
    $update_data = array(
        'hits_total' => $site_item['hits_total'] + 1,
        'hits_month' => 1,
        'hits_day' => 1,
        'date' => $date,
        'datem' => $datem
    );
} else {
    $update_data = array(
        'hits_total' => $site_item['hits_total'] + 1
    );
}

$DB->update('site', $update_data, array('id' => $site_item['id']));

$site_item = array_merge($site_item, $update_data);

preg_match("/^(http:\/\/|https:\/\/)?([^\/]+)/i", $site_item['url'], $matches);
$domain = $matches[2];
$page_title = $site_item['name'] . ' - ' . $conf['title'];
$keywords = $site_item['keywords'];
$description = $site_item['introduce'];
if (strlen($description) > 240) {
    $description = mb_substr($description, 0, 80, "utf-8") . "..";
}
$cate_list = $DB->findAll('category', '*', '', 'sid asc');
$cate_item = $DB->find('category', 'id,catename,alias', array('catename' => $site_item['catename']), 'sid asc');
$site_list = $DB->findAll('site', 'id,name,alias,img', array('catename' => $site_item['catename']), 'lid asc', 14);
?>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title><?php echo $page_title; ?></title>
    <meta name="keywords" content="<?php echo $keywords; ?>">
    <meta name="description" content="<?php echo $description; ?>">
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/assets/css/ozui.min.css" />
    <link rel="stylesheet" type="text/css" href="/templates/default/css/style.css" />
    <link rel="stylesheet" type="text/css" href="/templates/default/css/background.css" />
    
    <!-- jQuery库 -->
    <script type="text/javascript" src="/assets/jquery/1.12.4/jquery.min.js"></script>
    
    <?php echo $conf['script_header']; ?>

</head>

<body>
<div class="background-container"></div>
<?php require('./home/header.php'); ?>
<?php require('./home/banner.php'); ?>

<ul class="category">
    <li><a href="<?php echo $site_url; ?>"><span>返回首页</span> <i class="fa fa-reply fa-fw"></i></a></li>
<?php foreach($cate_list as $row) { ?>
    <li><a href="<?php echo $site_url; ?>/category.php?id=<?php echo $row['id'];?>" class="<?php if ($site_item['catename'] == $row['catename']) { echo "active"; }; ?>"><span><?php echo $row['catename'];?></span> <i class="fa <?php echo $row['icon'];?> fa-fw"></i></a></li>
<?php } ?>
</ul>

<div class="container">
    <div class="card board">
        <span class="icon"><i class="fa fa-map-signs fa-fw"></i></span>
        <span><a href="<?php echo $site_url; ?>">导航首页</a>&nbsp;»&nbsp;</span>
        <span><a title="<?php echo $site_item['catename']; ?>" href="<?php echo empty($cate_item['alias']) ? $site_url . '/category.php?id=' . $cate_item['id'] : $site_url . '/category.php?alias=' . $cate_item['alias']; ?>"><?php echo $site_item['catename']; ?></a>&nbsp;»&nbsp;</span>
        <span><?php echo $site_item['name']; ?></span>
    </div>
    <div class="card">
        <div class="card-body">
            <div class="part-main">
                <span class="site-name"><?php echo $site_item['name']; ?></span>
                <span class="oz-xs-12 oz-sm-6 oz-lg-4">站点域名：<?php echo $domain; ?></span>
                <span class="oz-xs-12 oz-sm-6 oz-lg-4">备案号：<?php echo !empty($site_item['icp']) ? $site_item['icp'] : '无'; ?></span>
                <span class="oz-xs-12 oz-sm-6 oz-lg-4">联系方式：<?php echo !empty($site_item['contact']) ? $site_item['contact'] : '无'; ?></span>
                <span class="oz-xs-12 oz-sm-6 oz-lg-4">站点星级：<img class="lazy-load" src="/templates/default/images/star/<?php echo min(max(intval($site_item['star']), 1), 5); ?>.png"></span>
                <span class="oz-xs-12 oz-sm-6 oz-lg-4">是否推荐：<?php echo $site_item['tui'] == 1 ? "<span color=red>是</span>" : '否'; ?></span>
                <span class="oz-xs-6 oz-sm-6 oz-lg-4">日浏览数：<?php echo $site_item['hits_day']; ?> 次</span>
                <span class="oz-xs-6 oz-sm-6 oz-lg-4">月浏览数：<?php echo $site_item['hits_month']; ?> 次</span>
                <span class="oz-xs-6 oz-sm-6 oz-lg-4">总浏览数：<?php echo $site_item['hits_total']; ?> 次</span>
                <span class="oz-xs-6 oz-sm-6 oz-lg-4">所属分类：<a title="<?php echo $site_item['catename']; ?>" href="<?php if (empty($cate_item['alias'])) {
                                                                                                                        echo $site_url . "/category.php?id={$cate_item['id']}";
                                                                                                                    } else {
                                                                                                                        echo $site_url . "/category.php?alias={$cate_item['alias']}";
                                                                                                                    }; ?>"><?php echo $site_item['catename']; ?></a></span>
                <span class="oz-xs-6 oz-sm-6 oz-lg-4">百度权重：<img class="lazy-load" src="https://baidurank.aizhan.com/api/br?domain=<?php echo $domain; ?>&style=images"></span>
                <span class="oz-xs-6 oz-sm-6 oz-lg-4">移动权重：<img class="lazy-load" src="https://baidurank.aizhan.com/api/mbr?domain=<?php echo $domain; ?>&style=images"></span>
                <span class="oz-xs-6 oz-sm-6 oz-lg-4">360权重：<img class="lazy-load" src="https://sorank.aizhan.com/api/br?domain=<?php echo $domain; ?>&style=images"></span>
                <span class="oz-xs-12 oz-sm-6 oz-lg-4">收录日期：<?php echo $site_item['time']; ?></span>
                <span class="oz-xs-12 oz-sm-12 oz-lg-12">快捷查询：
                    <a title="Whois查询" href="http://whois.chinaz.com/<?php echo $domain; ?>" target="_blank">Whois查询</a> | 
                    <a title="备案查询" href="http://icp.chinaz.com/<?php echo $domain; ?>" target="_blank">必应查询</a> | 
                    <a title="必应权重" href="https://rank.chinaz.com/bing/<?php echo $domain; ?>" target="_blank">备案查询</a> |
                    <a title="综合查询" href="http://seo.chinaz.com/?host=<?php echo $domain; ?>" target="_blank">综合查询</a> | 
                    <a title="百度收录查询" href="http://tool.chinaz.com/baidu/?wd=<?php echo $domain; ?>" target="_blank">百度收录查询</a>
                </span>
            </div>
            <div class="part-side">
                <div class="site-img">
                    <img class="lazy-load" src="/assets/images/loading.gif" data-src="<?php echo $conf['shots_api']; ?><?php echo $site_item['url']; ?>">
                </div>
                <a title="<?php echo $domain; ?>" href="<?php echo $site_url; ?>/go.php?url=<?php echo $site_item['url']; ?>" target="_blank" data-id="1" class="oz-btn oz-btn-lg oz-bg-orange oz-btn-block">
                    <i class="fa fa-telegram fa-fw" aria-hidden="true"></i> 网站直达
                </a>
                <button class="oz-btn oz-btn-lg oz-bg-blue like-btn oz-btn-block" rel="<?php echo $site_item['id']; ?>"><i class="fa fa-heart-o fa-fw" aria-hidden="true"></i> 点赞支持 [<?php echo $site_item['like']; ?>]</button>
                <a href="http://seo.chinaz.com/<?php echo $site_item['url']; ?>" target="_blank" data-id="1" class="oz-btn oz-btn-lg oz-bg-green oz-btn-block">
                    <i class="fa fa-external-link fa-fw" aria-hidden="true"></i> 综合查询
                </a>
                <button id="feedbackBtn" data-site-id="<?php echo $site_item['id']; ?>" data-site-name="<?php echo $site_item['name']; ?>" class="oz-btn oz-btn-lg oz-bg-red oz-btn-block">
                    <i class="fa fa-exclamation-triangle fa-fw" aria-hidden="true"></i> 异常反馈
                </button>
            </div>
        </div>
    </div>
    <div class="card">
        <div class="card-head">
            <i class="fa fa-wpforms fa-fw" aria-hidden="true"></i> 网站信息
        </div>
        <div class="card-body content">
            <!-- 网站缩略图 -->
            <div class="snapshot-container">
                <div class="snapshot">
                    <a href="<?php echo $site_item['url']; ?>" target="_blank" style="display: block; text-decoration: none;">
                        <img class="lazy-load" src="/assets/images/loading.gif" 
                             data-src="<?php echo $conf['shots_api']; ?><?php echo $site_item['url']; ?>" 
                             alt="<?php echo $site_item['name']; ?> 网站截图" 
                             style="max-width: 100%; height: auto; max-height: 500px; border-radius: 12px; object-cover; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);">
                    </a>
                </div>
            </div>
            
            <!-- 网站信息 -->
            <div class="site-info-container">
                <p><b>站点域名：</b><font color="#FF0000"><?php echo $domain; ?></font> </p>
                <p><b>站点名称：</b><font color="#FF0000"><?php echo $site_item['name']; ?></font> </p>
                <p><b>站点关键词：</b><font color="#FF0000"><?php echo !empty($site_item['keywords']) ? $site_item['keywords'] : '暂无关键词信息'; ?></font> </p>
                <p><b>站点描述：</b><font color="#FF0000"><?php echo !empty($site_item['introduce']) ? $site_item['introduce'] : '暂无描述信息'; ?></font> </p>
            </div>
            
                .snapshot-container {
                    text-align: center;
                    margin-bottom: 20px;
                }
                .snapshot {
                    position: relative;
                    display: inline-block;
                    transition: transform 0.3s ease;
                }
                .snapshot:hover {
                    transform: scale(1.02);
                }
                .snapshot a:hover .lazy-load {
                    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.12);
                }
                .site-info-container {
                    background-color: #f8f9fa;
                    padding: 15px;
                    border-radius: 8px;
                    border: 1px solid #e9ecef;
                }
                .site-info-container p {
                    margin: 8px 0;
                    font-size: 14px;
                    line-height: 1.6;
                }
            </style>
        </div>
    </div>

    <div class="card">
        <div class="card-head">
        <i class="fa fa-line-chart" aria-hidden="true" /></i> 站点数据评估
        </div>
        <p style="line-height:24px"><span><i class="fa fa-chart-line"></i><?php echo $site_item['name']; ?></span>的网址是：<?php echo $domain; ?></p>
         <p>该站点自收录迄直至此刻，累计点击人数已经达到<?php echo $site_item['hits_total']; ?>次。</p>
         <p>该站点收录来源于网络，<font color="#FF0000"><?php echo $conf['title']; ?></font>不保证外部链接的实时性、准确性和完整性。对于该外部链接的指向，不由<?php echo $conf['title']; ?>实际控制。</p>
         <p>收录时，该网页上属于合规合法的内容，以静态页面储存于此，后期网页的内容如出现违规，可以直接联系网站管理员进行删除。
         <p>该站点内容与<?php echo $conf['title']; ?>无关。</p>
    </div>
    
    <div class="card">
      <div class="card-head">
      <i class="fa fa-trophy" aria-hidden="true"></i>申请收录的好处
      </div>
      <p>让您的网站更快、更多地被搜索引擎收录</p>
      <p>让您的网站名称的关键词在搜索引擎的搜索结果的第一页甚至第一个</p>
      <p>通过本站这个分类目录平台从而给您的网站带来巨大流量</p>
      <p>如您网站被搜索引擎屏蔽,<?php echo $conf['title']; ?>永久缓存贵站信息，通过这个页面浏览者照样借助<?php echo $conf['title']; ?>进入您的网站！</p>
      <p> 
      <font color="#ff0000">提交收录申请后，请在贵站首页添加本站友链</font></P> 
      <p> <span style="color: #000000; font-size: 14px;"><strong>&lt;a href="<?php echo $site_url; ?>" target="_blank"&gt;<?php echo $conf['title']; ?>&lt;/a&gt;</strong></span>
      </p>      
    </div>

    <div class="card">
        <div class="card-head">
            <i class="fa fa-magnet fa-fw" aria-hidden="true"></i> 相关站点
        </div>
        <div class="card-body">
        <?php foreach($site_list as $rows) { ?>
            <a
                class="item"
                href="<?php echo empty($rows['alias']) ? $site_url . '/site.php?id=' . $rows['id'] : $site_url . '/site.php?alias=' . $rows['alias']; ?>"
                title="<?php echo $rows['name']; ?>"
                data-id="<?php echo $rows['id']; ?>"
            >
                <span class="icon"><img class="lazy-load" src="/assets/images/loading.gif" data-src="<?php echo $rows['img']; ?>" onerror="this.src='/assets/images/default_ico.png';this.onerror=null;this.classList.add('load-failed');" onload="if(this.width == 1 && this.height == 1) {this.src='/assets/images/default_ico.png';this.classList.add('load-failed');}" style="min-width:16px;min-height:16px;"></span>
                <span class="name"><?php echo $rows['name']; ?></span>
            </a>
        <?php } ?>
        </div>
    </div>
</div>


<?php require('./home/footer.php'); ?>

<script>
$(function() {
    // 异常反馈按钮点击事件
    $('#feedbackBtn').click(function() {
        var siteId = $(this).data('site-id');
        var siteName = $(this).data('site-name');
        
        // 确保siteId是整数
        siteId = parseInt(siteId);
        
        // 创建反馈表单HTML
        var html = '<div style="padding: 20px;">' +
            '<form id="feedbackForm">' +
            '<input type="hidden" name="site_id" value="' + siteId + '">' +
            '<div class="form-group" style="margin-bottom: 15px;">' +
            '<label for="feedback_type" style="display: block; margin-bottom: 5px;">反馈类型 <span style="color:red">*</span></label>' +
            '<select class="form-control" id="feedback_type" name="feedback_type" required style="width: 100%; padding: 8px;">' +
            '<option value="">请选择反馈类型</option>' +
            '<option value="链接失效">链接失效</option>' +
            '<option value="内容违规">内容违规</option>' +
            '<option value="信息错误">信息错误</option>' +
            '<option value="其他问题">其他问题</option>' +
            '</select>' +
            '</div>' +
            '<div class="form-group" style="margin-bottom: 15px;">' +
            '<label for="feedback_desc" style="display: block; margin-bottom: 5px;">问题描述 <span style="color:red">*</span></label>' +
            '<textarea class="form-control" id="feedback_desc" name="feedback_desc" rows="5" required placeholder="请详细描述您遇到的问题，以便我们更好地处理" style="width: 100%; padding: 8px;"></textarea>' +
            '</div>' +
            '<div class="form-group" style="margin-bottom: 15px;">' +
            '<label for="contact_info" style="display: block; margin-bottom: 5px;">联系方式（可选）</label>' +
            '<input type="text" class="form-control" id="contact_info" name="contact_info" placeholder="留下您的邮箱或QQ，方便我们与您联系" style="width: 100%; padding: 8px;">' +
            '</div>' +
            '<div class="form-group" style="margin-bottom: 15px;">' +
            '<div style="background-color: #f8f9fa; padding: 10px; border-radius: 4px;">' +
            '感谢您的反馈，我们会尽快处理您反映的问题。为防止滥用，同一IP每小时最多可提交3次反馈。' +
            '</div>' +
            '</div>' +
            '</form>' +
            '</div>';
    
        // 使用layer.js打开模态框
        var index = layer.open({
            type: 1,
            title: '站点异常反馈 - ' + siteName,
            content: html,
            area: ['90%', 'auto'],
            maxWidth: 600,
            btn: ['提交反馈', '关闭'],
            btn1: function(index, layero) {
                // 不使用jQuery的AJAX，改用原生XMLHttpRequest确保正确处理响应
                var xhr = new XMLHttpRequest();
                xhr.open('POST', '/api/feedback.php', true);
                xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
                
                // 显示加载中状态
                var loadingIndex = layer.load(1, {shade: [0.1,'#fff']});
                
                xhr.onreadystatechange = function() {
                    if (xhr.readyState === 4) {
                        layer.close(loadingIndex);
                        layer.close(index);
                        
                        try {
                            // 手动解析JSON字符串
                            var response = JSON.parse(xhr.responseText);
                            
                            // 显示提示信息
                            if (response.code == 0) {
                                layer.msg('反馈提交成功，感谢您的支持！', {icon: 1, time: 2000});
                            } else {
                                layer.msg('提交失败：' + response.msg, {icon: 2, time: 2000});
                            }
                        } catch (e) {
                            layer.msg('网络异常，请稍后重试', {icon: 2, time: 2000});
                        }
                    }
                };
                
                // 构建表单数据字符串，确保site_id以原始数字形式发送
                var formData = 'site_id=' + siteId +
                               '&feedback_type=' + encodeURIComponent($('#feedback_type').val()) +
                               '&feedback_desc=' + encodeURIComponent($('#feedback_desc').val()) +
                               '&contact_info=' + encodeURIComponent($('#contact_info').val());
                
                xhr.send(formData);
                
                return false; // 阻止默认关闭
            }
        });
    });
});
</script>

<script>
// 确保site.php页面的图标显示稳定
$(function() {
    // 为相关站点区域的图片添加额外的错误处理
    $('.card-body .icon img').each(function() {
        let img = $(this);
        // 检查图片是否已经加载失败
        if (img[0].naturalWidth === 0 || img[0].naturalHeight === 0) {
            img.attr('src', '/assets/images/default_ico.png');
            img.addClass('load-failed');
        }
    });
    
    // 重新触发一次懒加载处理，确保所有图片状态正确
    if (typeof lazyRender === 'function') {
        lazyRender($('.lazy-load'));
    }
});
</script>
</body>
</html>